package com.ajk.server.utils;

import java.text.SimpleDateFormat;

public class ThreadLocalSimpleDateFormater {
	private static final ThreadLocal<SimpleDateFormat> simpleDateFormatThreadLocal = new ThreadLocal<>();
	private static final ThreadLocal<SimpleDateFormat> simpleDateFormatThreadLocalYYYYMMDD = new ThreadLocal<>();
	
	public static SimpleDateFormat getSimpleDateFormatYYYYMMDD(){
		SimpleDateFormat simpleDateFormat = simpleDateFormatThreadLocalYYYYMMDD.get();
		if(simpleDateFormat!=null){
			
		}else{
			synchronized (ThreadLocalSimpleDateFormater.class) {
				if(simpleDateFormat==null){
					simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
					simpleDateFormatThreadLocalYYYYMMDD.set(simpleDateFormat);	
				}
			}
		}
		return simpleDateFormat;
	}
	
	public static SimpleDateFormat getSimpleDateFormat(){
		SimpleDateFormat simpleDateFormat = simpleDateFormatThreadLocal.get();
		if(simpleDateFormat!=null){
			
		}else{
			synchronized (ThreadLocalSimpleDateFormater.class) {
				if(simpleDateFormat==null){
					simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
					simpleDateFormatThreadLocal.set(simpleDateFormat);	
				}
			}
		}
		return simpleDateFormat;
	}
}
